// components/waterfall-item/waterfall-item.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    itemData: {
      type: Object
    },
    imgList: {
      type: Array
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    compare: function (property, bol) {
      return function (a, b) {
        var value1 = a[property];
        var value2 = b[property];
        if (bol) {
          return value1 - value2;
        } else {
          return value2 - value1;
        }
      }
    },
    //预览图片
    previewImage: function (e) {
      var current = e.target.dataset.src;
      var list = e.target.dataset.list;
      let newlist = [];
      //提取数组的部分元素组成一个新数组
      list.forEach(item => {
        item.forEach(newItem => {
          let newdata = {};
          newdata.id = newItem.id;
          newdata.imgUrl = newItem.imgUrl;
          newlist.push(newdata)
        });
      });
      newlist.sort(this.compare("id",true));
      console.log("列表：", newlist)
      var imgList = [];
      newlist.forEach(item => {
        imgList.push(item.imgUrl)
      });
      wx.previewImage({
        current: current, //当前点击的图片链接
        urls: imgList //图片数组
      })
    },
  }
})